package com.enation.app.web.core.action.api;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.enation.app.base.core.action.api.ValidCodeApiController;
import com.enation.framework.action.JsonResult;
import com.enation.framework.context.webcontext.ThreadContextHolder;
import com.enation.framework.context.webcontext.WebSessionContext;
import com.enation.framework.util.JsonResultUtil;

/**
 * 
 * @function 验证验证码是否正确
 * @author 闯哥
 * @time 2016年12月1日 下午9:23:02
 */
@Controller
@RequestMapping("/api/checkCode")
public class CheckCodeController {

	@ResponseBody
	@RequestMapping(value = "/check")
	public JsonResult check(String checkCode) {

		checkCode = checkCode.toLowerCase();
		WebSessionContext sessonContext = ThreadContextHolder
				.getSessionContext();
		Object realCode = ("" + sessonContext
				.getAttribute(ValidCodeApiController.SESSION_VALID_CODE
						+ "admin")).toLowerCase();

		if (!checkCode.equals(realCode)) {
			return JsonResultUtil.getErrorJson("验证码输入错误");

		}

		return JsonResultUtil.getSuccessJson("验证通过！");
	}
}
